package com.lanqiao.companymanage.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lanqiao.companymanage.entity.Admin;
import com.lanqiao.companymanage.service.AdminChangePasswordService;
import com.lanqiao.companymanage.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WangJunJie
 */


@RestController
@RequestMapping("/AdminChangePassword")
@Api(tags = "管理员修改密码")
public class AdminChangePasswordController {


    @Autowired
    AdminChangePasswordService adminChangePasswordService;

    @PostMapping("/AdminChange")
    @ApiOperation(value = "根据名字修改")
    public Result changePassword(@Param("username") String username, @Param("userPassword") String newPassword) {
        UpdateWrapper<Admin> adminUpdateWrapper = new UpdateWrapper<>();
        boolean update = adminChangePasswordService.update(adminUpdateWrapper.set("password", newPassword).eq("username", username));
        if (update){
            return Result.success("修改成功");
        }
        return Result.err("修改失败");

    }


}
